﻿using MySql.Data.MySqlClient;
using System.Collections.Generic;

namespace Library
{
    class UserSql
    {
        private string uid, upwd;
        private string url = "server=192.168.99.57;port=3306;user=root;password=123456;database=book;Charset=utf8;SslMode=None;";
        private string sql = "";
        private MySqlDataReader reader = null;
        public void setInfo(string id,string pwd)
        {
            this.uid = id;
            this.upwd = pwd;
        }

        public Queue<string> getInfo()
        {
            Queue<string> queue = new Queue<string>();
            queue.Enqueue(this.uid);
            queue.Enqueue(this.upwd);
            return queue;
        }

        public int changePwd(string id,string pwd)
        {
            int sign = 0;
            string sql = "update userinfo set Passwd='" + pwd + "' where UserId='" + id + "';";
            Debug debug = new Debug();
            debug.console(sql);
            MySqlConnection mySqlConnection = new MySqlConnection(url);
            try
            {
                mySqlConnection.Open();
                MySqlCommand mySqlCommand = new MySqlCommand(sql, mySqlConnection);
                sign = mySqlCommand.ExecuteNonQuery();
                mySqlConnection.Close();
            }
            catch
            {
                mySqlConnection.Close();
            }
            finally
            {
                mySqlConnection.Close();
            }
            return sign;
        }
    }
}
